(ns use-fx-clj.table
  (:require [fx-clj.core :as fx]
            [freactive.core :as f]
            [fx-clj.core.extensibility :refer [convert-arg] :as ext])
  (:import (javafx.application Platform)
           (javafx.collections FXCollections)
           (javafx.scene.control.cell MapValueFactory)))

(defmethod convert-arg [clojure.lang.Keyword java.lang.String] [a b c]
  (println a b c)
  b)

(def state (f/atom {:data [{:id 1 :text "a"}
                           {:id 2 :text "b"}
                           {:id 3 :text "c"}]}))

(def table-data0 (f/cursor state :data))
(def table-data (f/rx (FXCollections/observableList @table-data0)))

(defn create-view []
  (let [table (fx/table-view
                {:columns [(fx/table-column {:text               "id"
                                             :cell-value-factory (MapValueFactory. :id)})
                           (fx/table-column {:text               "text"
                                             :cell-value-factory (MapValueFactory. :text)})]
                 :items   table-data})]
    table))

(Platform/setImplicitExit true)
(fx/sandbox #'create-view)